import { Client } from "../../dist/esm/index.js";
const send2Parent = document.querySelector("#send2Parent");
const invokeParent = document.querySelector("#invokeParent");
export const init = async () => {
  const client = new Client({
    target: window.parent,
    handlers: {
      // 子页面的处理函数
      info: console.info,
    },
  });
  // 建立连接
  client.mount();
  // 监听 "msg" 事件
  client.on("msg", console.log.bind(null, "son收到消息"));
  send2Parent.addEventListener("click", () => {
    // 发送 "msg" 消息
    client.send({ type: "msg", data: { name: "son" } });
  });
  invokeParent.addEventListener("click", () => {
    // 调用父页面的info函数
    client.invokeHandler({ type: "log", data: ["log"] });
  });
};
